﻿@{
    ViewBag.Title = "";
    Layout = "~/Views/Shared/_Index.cshtml";
 }
@using Raffles.OA.Data
@using Raffles.OA.Utility
<section class="content">
    <div class="row">
         <div class="col-xs-12">
              <div class="box box-info">
                   <div class="box-body">
                        <div class="table-responsive">
                            <div class="btn-group-sm" id="toolbar" role="group">
                                <a id="btnClean" authorize="yes" class="btn btn-danger" onclick="cleanLog()"><i class="fa fa-trash"></i> 清空</a>
                                <div class="col-sm-3 pull-right">
                                    <div class="input-group input-group-sm">
                                        <input type="text" id="keyWord" col="KeyWord" class="form-control" placeholder="请输入关键字查询" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-primary" onclick="searchGrid()"><i class="fa fa-search"></i></button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                             <table id="gridTable" class="table table-hover table-striped text-nowrap">
                             </table>
                        </div>
                   </div>
              </div>
         </div>
    </div>
</section>

<script type="text/javascript">
    $(function () {
        initGrid();
    });

    function initGrid() {
        $('#gridTable').frameTable({
            url: '@Url.Action("GetPageListJson", "Log")',
            sortName: 'CreateOn',
            sortOrder: 'Desc',
            columns: [
                 {
                    field: 'LogType', title: '操作类型', halign: "center", align: "center",
                    formatter: function (value, item, index) {
                        return '@DbLogType.Login.GetDescription()'
                    }
                },
                {
                    field: 'ClassName', title: '请求路由', halign: "center", align: "center",
                     formatter: function (value, row, index) {
                         return row.ClassName + (row.MethodName == null ? "" : row.MethodName);
                    }
                },
                { field: 'ExecuteTime', title: '耗时(ms)', halign: "center", align: "center" },
                { field: 'Description', title: '客户端', halign: "center", align: "center" },
                { field: 'OperateIPAddress', title: 'IP地址', halign: "center", align: "center" },
                {
                    field: 'ExecuteResult', title: '执行状态', align: 'center',
                    formatter: function (value, row, index) {
                        if (value == @((int)OperateStatusEnum.Success)) {
                            return '<span class="label label-success">' + "成功" + '</span>';
                        } else {
                            return '<span class="label label-danger">' + "失败" + '</span>';
                        }
                    }
                },
                { field: 'OperateRealName', title: '操作人', halign: "center", align: "center" },
                { field: 'CreatedOn', title: '操作日期', halign: "center", align: "center", sortable: true },
            ],
            queryParams: function (params) {
                 var pagination = $('#gridTable').frameTable('getPagination', params);
                 var queryString = $('#toolbar').getWebControls(pagination);
                 return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').frameTable('search');
    }

    //日志清空
    function cleanLog() { 
        frame.confirm('确定要清空所有日志吗', function () {
            frame.ajax({
                url: '@Url.Action("LogClean","Log")', 
                type: "post",
                success: function (obj) {
                    if (obj.success) {
                        frame.msgSuccess(obj.message);
                        searchGrid();
                    }
                    else {
                        frame.msgError(obj.message);
                    }
                }
            });
        });
    }
</script>
